// 引入http请求插件
import Request from "./libs/request";
// 防抖、节流方法
import { debounce, throttle } from "./libs/utils/lodash";
// 将verify内导出的函数放到verify中，方便在$endless上进行挂载
import * as verify from "./libs/utils/lodash/verify";
// 将工具函数全部导出，方便用户自行引用
export * from "./libs/utils";
import {
  timeFormat,
  timeFrom,
  getInterval,
  daysBetweenDates,
} from "./libs/utils/lodash/date";

const endlessUtil = {
  debounce,
  throttle,
  date: {
    timeFormat,
    timeFrom,
    getInterval,
    daysBetweenDates
  },
  verify,
};

/**
 * @description 工具类的初始化函数，包含http请求<br>
 * 函数接受以下泛型变量<br>
 * 泛型T：作为http请求所返回的data变量的类型，默认为Record<string, any>类型
 */
const utilInstall = <T = Record<string, any>>() => {
  uni.$endless = {
    // 全局挂载http请求插件
    http: new Request<T>(),
    util: endlessUtil,
  };
};

export {utilInstall, endlessUtil };
